package com.epam.training.domain;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;

/**
 * The persistent class for the admin database table.
 * 
 */
@Entity
@Table(name = "admin")
@DiscriminatorValue("admin")
@PrimaryKeyJoinColumn(name = "admin_id", referencedColumnName = "user_id")
@NamedQuery(name = "Admin.findAll", query = "SELECT a FROM Admin a")
public class Admin extends User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Column(name = "admin_id", insertable = false, updatable = false, unique = true, nullable = false)
	private Integer adminId;

	@Temporal(TemporalType.DATE)
	@Column(name = "last_acces")
	private Date lastAcces;

	@Column(length = 10)
	private String name;

	public Admin() {
	}

	/**
	 * 
	 * @param adminId
	 * @param lastAccess
	 * @param name
	 */
	public Admin(Integer adminId, Date lastAccess, String name) {
		this.adminId = adminId;
		this.lastAcces = lastAccess;
		this.name = name;
	}

	public Integer getAdminId() {
		return this.adminId;
	}

	public void setAdminId(Integer adminId) {
		this.adminId = adminId;
	}

	public Date getLastAcces() {
		return this.lastAcces;
	}

	public void setLastAcces(Date lastAcces) {
		this.lastAcces = lastAcces;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((adminId == null) ? 0 : adminId.hashCode());
		result = prime * result
				+ ((lastAcces == null) ? 0 : lastAcces.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Admin other = (Admin) obj;
		if (adminId == null) {
			if (other.adminId != null)
				return false;
		} else if (!adminId.equals(other.adminId))
			return false;
		if (lastAcces == null) {
			if (other.lastAcces != null)
				return false;
		} else if (!lastAcces.equals(other.lastAcces))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
}
